import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_learn_demo/localreferesh/local_refresh_test.dart';
import 'package:flutter_learn_demo/notifier/change_notifier_test.dart';
import 'package:flutter_learn_demo/page_cache/keep_alive_test.dart';

import 'localreferesh2/local_refresh_test2.dart';

class Category extends StatefulWidget {

  const Category({super.key});

  @override
  State createState() => CategoryState();

}

class CategoryState extends State<Category> with AutomaticKeepAliveClientMixin {

  final Random random = Random();

  List dataSet = [
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'I',
    'J',
    'K',
    'L',
    'M',
    'N',
    'O',
    'P',
    'Q',
    'R',
    'S',
    'T',
    'U',
    'V',
    'W',
    'X',
    'Y',
    'Z'
  ];

  List colorDataSet = [
    Colors.red,
    Colors.cyanAccent,
    Colors.pink,
    Colors.indigoAccent,
    Colors.yellow,
    Colors.deepPurple,
  ];

  @override
  void initState() {
    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    print('Widget build(BuildContext context)');
    return SingleChildScrollView(
      child: Column(
               children: List.generate(dataSet.length, (index) {
                  var edgeInsets = (dataSet.length - 1) == index
                      ? const EdgeInsets.only(top: 10,left: 5,right: 5,bottom: 10)
                      :  const EdgeInsets.only(top: 10,left: 5,right: 5);
                  return Container(
                     margin: edgeInsets,
                     height: 60,
                     child: Material(
                             child: Ink(
                                 decoration: BoxDecoration(color:colorDataSet[random.nextInt(colorDataSet.length)],
                                 borderRadius: BorderRadius.circular(10),),
                                 child: InkWell(
                                       borderRadius: BorderRadius.circular(10),
                                 onTap: () {
                                    switch(index) {
                                      case 0:{
                                         Navigator.of(context).pushReplacementNamed("buttons");
                                         break;
                                      }
                                      case 1:{
                                        Navigator.of(context).pushReplacementNamed("turnbox");
                                        break;
                                      }
                                      case 2:{
                                        Navigator.of(context).pushReplacementNamed("scrollcontrollertest");
                                        break;
                                      }
                                      case 3:{
                                        Navigator.of(context).pushReplacementNamed("scrollnotificationtest");
                                        break;
                                      }
                                      case 4:{
                                        //这种方式跳转界面  不会退出当前界面   不需要路由注册
                                        Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
                                           return const ChangeNotifierTest();
                                        }));
                                        break;
                                      }
                                      case 5:{
                                        //这种方式跳转界面  不会退出当前界面   不需要路由注册
                                        Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
                                          return const LocalRefreshTest();
                                        }));
                                        break;
                                      }
                                      case 6:{
                                        //这种方式跳转界面  不会退出当前界面   不需要路由注册
                                        Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
                                          return const LocalRefreshTest2();
                                        }));
                                        break;
                                      }
                                      case 7:{
                                        //这种方式跳转界面  不会退出当前界面   不需要路由注册
                                        Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
                                          return const KeepAliveTest();
                                        }));
                                        break;
                                      }
                                      default:{
                                         break;
                                      }
                                    }
                                 },
                                child: Center(
                                  child: Text(dataSet[index],style:
                                  const TextStyle(color: Colors.black,fontSize: 15),textAlign: TextAlign.center,),),
                             ),
                         ),
                    ),
                );
             }
         )
       ),
     );
  }

  @override
  bool get wantKeepAlive => true;

}